<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.10"/>
<title>nrf/rfhelp.c File Reference</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../vesc.jpg"/></td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.10 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="../../index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="../../pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="../../modules.html"><span>Modules</span></a></li>
      <li><a href="../../annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="../../files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="../../search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="../../search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="../../files.html"><span>File&#160;List</span></a></li>
      <li><a href="../../globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../dir_34bea165460058977cae49dd7fa81d62.html">nrf</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">rfhelp.c File Reference</div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><code>#include &quot;<a class="el" href="../../de/da9/rfhelp_8h_source.html">rfhelp.h</a>&quot;</code><br />
<code>#include &quot;<a class="el" href="../../df/db2/rf_8h_source.html">rf.h</a>&quot;</code><br />
<code>#include &quot;ch.h&quot;</code><br />
<code>#include &quot;hal.h&quot;</code><br />
<code>#include &quot;<a class="el" href="../../dc/de6/crc_8h_source.html">crc.h</a>&quot;</code><br />
<code>#include &lt;string.h&gt;</code><br />
<code>#include &lt;stdbool.h&gt;</code><br />
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:aa69935e38607e31894a53507bf283cb3"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/db9/rfhelp_8c.html#aa69935e38607e31894a53507bf283cb3">rfhelp_init</a> (void)</td></tr>
<tr class="separator:aa69935e38607e31894a53507bf283cb3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:acaf96bd25ff23746998cdccdd218e6f0"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/db9/rfhelp_8c.html#acaf96bd25ff23746998cdccdd218e6f0">rfhelp_restart</a> (void)</td></tr>
<tr class="separator:acaf96bd25ff23746998cdccdd218e6f0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6c211deeed0c279771931901bdc836c3"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/db9/rfhelp_8c.html#a6c211deeed0c279771931901bdc836c3">rfhelp_send_data</a> (char *data, int len)</td></tr>
<tr class="separator:a6c211deeed0c279771931901bdc836c3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ab117edf59c58a37096ce943554edca2b"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/db9/rfhelp_8c.html#ab117edf59c58a37096ce943554edca2b">rfhelp_send_data_crc</a> (char *data, int len)</td></tr>
<tr class="separator:ab117edf59c58a37096ce943554edca2b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a16e9c5564c9de7bbbfe46e0a2aae1420"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/db9/rfhelp_8c.html#a16e9c5564c9de7bbbfe46e0a2aae1420">rfhelp_read_rx_data</a> (char *data, int *len, int *pipe)</td></tr>
<tr class="separator:a16e9c5564c9de7bbbfe46e0a2aae1420"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:afd75aa9e86ee2b60d2702bcdcd190aa0"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/db9/rfhelp_8c.html#afd75aa9e86ee2b60d2702bcdcd190aa0">rfhelp_read_rx_data_crc</a> (char *data, int *len, int *pipe)</td></tr>
<tr class="separator:afd75aa9e86ee2b60d2702bcdcd190aa0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a27b2e4ffcc669c5ef100abcb076d92fe"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/db9/rfhelp_8c.html#a27b2e4ffcc669c5ef100abcb076d92fe">rfhelp_rf_status</a> (void)</td></tr>
<tr class="separator:a27b2e4ffcc669c5ef100abcb076d92fe"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af893959023105d70ac3a8c6a3b27fe44"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/db9/rfhelp_8c.html#af893959023105d70ac3a8c6a3b27fe44">rfhelp_set_tx_addr</a> (const char *addr, int addr_len)</td></tr>
<tr class="separator:af893959023105d70ac3a8c6a3b27fe44"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a944b325bab3dd1edb9f50ac4a4154ef3"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/db9/rfhelp_8c.html#a944b325bab3dd1edb9f50ac4a4154ef3">rfhelp_set_rx_addr</a> (int pipe, const char *addr, int addr_len)</td></tr>
<tr class="separator:a944b325bab3dd1edb9f50ac4a4154ef3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6cb5d26c73f4fb1b134e697ecc4cc7fb"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/db9/rfhelp_8c.html#a6cb5d26c73f4fb1b134e697ecc4cc7fb">rfhelp_power_down</a> (void)</td></tr>
<tr class="separator:a6cb5d26c73f4fb1b134e697ecc4cc7fb"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a133dd762a1cc5477506a2cea0206b4d1"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/db9/rfhelp_8c.html#a133dd762a1cc5477506a2cea0206b4d1">rfhelp_power_up</a> (void)</td></tr>
<tr class="separator:a133dd762a1cc5477506a2cea0206b4d1"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<h2 class="groupheader">Function Documentation</h2>
<a class="anchor" id="aa69935e38607e31894a53507bf283cb3"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void rfhelp_init </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

</div>
</div>
<a class="anchor" id="a6cb5d26c73f4fb1b134e697ecc4cc7fb"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void rfhelp_power_down </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

</div>
</div>
<a class="anchor" id="a133dd762a1cc5477506a2cea0206b4d1"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void rfhelp_power_up </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

</div>
</div>
<a class="anchor" id="a16e9c5564c9de7bbbfe46e0a2aae1420"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int rfhelp_read_rx_data </td>
          <td>(</td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int *&#160;</td>
          <td class="paramname"><em>len</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int *&#160;</td>
          <td class="paramname"><em>pipe</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Read data from the RX fifo</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>Pointer to the array in which to store the data.</td></tr>
    <tr><td class="paramname">len</td><td>Pointer to variable storing the data length.</td></tr>
    <tr><td class="paramname">pipe</td><td>Pointer to the pipe on which the data was received. Can be 0.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>1: Read OK, more data to read. 0: Read OK -1: No RX data -2: Wrong length read. Something is likely wrong. </dd></dl>

</div>
</div>
<a class="anchor" id="afd75aa9e86ee2b60d2702bcdcd190aa0"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int rfhelp_read_rx_data_crc </td>
          <td>(</td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int *&#160;</td>
          <td class="paramname"><em>len</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int *&#160;</td>
          <td class="paramname"><em>pipe</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Same as rfhelp_read_rx_data, but will check if there is a valid CRC in the end of the payload.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>Pointer to the array in which to store the data.</td></tr>
    <tr><td class="paramname">len</td><td>Pointer to variable storing the data length.</td></tr>
    <tr><td class="paramname">pipe</td><td>Pointer to the pipe on which the data was received. Can be 0.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>1: Read OK, more data to read. 0: Read OK -1: No RX data -2: Wrong length read. Something is likely wrong. -3: Data read, but CRC does not match. </dd></dl>

</div>
</div>
<a class="anchor" id="acaf96bd25ff23746998cdccdd218e6f0"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void rfhelp_restart </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Re-init the rf chip </p>

</div>
</div>
<a class="anchor" id="a27b2e4ffcc669c5ef100abcb076d92fe"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int rfhelp_rf_status </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

</div>
</div>
<a class="anchor" id="a6c211deeed0c279771931901bdc836c3"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int rfhelp_send_data </td>
          <td>(</td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>len</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Set TX mode, send data, wait for result, set RX mode.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>The data to be sent.</td></tr>
    <tr><td class="paramname">len</td><td>Length of the data.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>0: Send OK. -1: Max RT. -2: Timeout </dd></dl>

</div>
</div>
<a class="anchor" id="ab117edf59c58a37096ce943554edca2b"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int rfhelp_send_data_crc </td>
          <td>(</td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>len</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Same as rfhelp_send_data, but will add a crc checksum to the end. This is useful for protecting against corruption between the NRF and the MCU in case there are errors on the SPI bus.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>The data to be sent.</td></tr>
    <tr><td class="paramname">len</td><td>Length of the data. Should be no more than 30 bytes.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>0: Send OK. -1: Max RT. -2: Timeout </dd></dl>

</div>
</div>
<a class="anchor" id="a944b325bab3dd1edb9f50ac4a4154ef3"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void rfhelp_set_rx_addr </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>pipe</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>addr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>addr_len</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

</div>
</div>
<a class="anchor" id="af893959023105d70ac3a8c6a3b27fe44"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void rfhelp_set_tx_addr </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>addr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>addr_len</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

</div>
</div>
</div><!-- contents -->
<hr class="footer"/><address class="footer"><small>
Generated by <a href="https://github.com/joshdellay" target="_new">Josh Dellay</a>